package com.nulldev.util.concurrency.threadIt.v4.utils.impls;

import com.nulldev.util.concurrency.threadIt.v4.asyncTasks.AsyncTaskCallback;
import com.nulldev.util.concurrency.threadIt.v4.emapi.ExecutionPreference;
import com.nulldev.util.concurrency.threadIt.v4.emapi.uft.Executable;
import com.nulldev.util.concurrency.threadIt.v4.emapi.uft.Returnable;

public class TEConditions {

	public static <T> void validExecutable(final Executable<T> exec) {
		if (exec == null)
			throw new NullPointerException("Executable<?> cannot be null!");
	}

	public static void validRunnable(final Runnable exec) {
		if (exec == null)
			throw new NullPointerException("Runnable cannot be null!");
	}

	public static void validPreference(final ExecutionPreference e) {
		if (e == null)
			throw new NullPointerException("ExecutionPreference cannot be null!");
	}

	public static <T> void validReturnable(final Returnable<T> r) {
		if (r == null)
			throw new NullPointerException("Returnable<?> cannot be null!");
	}

	public static <T> void validTaskCallback(final AsyncTaskCallback<T> asyncTaskCallback) {
		if (asyncTaskCallback == null)
			throw new NullPointerException("AsyncTaskCallback<?> cannot be null!");
	}

	public static <T> void warnIfRunning(final Executable<T> exec) {
		if (exec.isRunning()) {
			new RuntimeException("[WARNING] `" + exec + "` is already flagged as running!").printStackTrace();
			;
		}
	}

}
